class Ability
	include CanCan::Ability

	def initialize(user)
		user ||= User.new # guest user

		if user.role?(:admin)
			can :manage, :all

		elsif user.role? :mentor
			can :manage, Profile
			can :update, User
			can [:create, :read ], Comment
			can [:update, :destroy], Comment do |comment|
				comment && comment.profile.user == user
			end
			can [:new, :create, :read], [Award,Education,Research,Workplace,Activity,Family]
			can [:edit, :update,:destroy], [Award, Education, Research, Workplace,Activity,Family] do |award|
				award && award.profile.user == user
			end

		elsif user.role? :staff
			can :manage, Profile
			can :update, User
			can [:create, :read], Comment
			can [:update, :destroy], Comment do |comment|
				comment && comment.profile.user == user
			end
			can [:new, :create, :read], [Award,Education,Research,Workplace,Activity,Family]
			can [:edit, :update,:destroy], [Award, Education, Research, Workplace,Activity,Family] do |award|
				award && award.profile.user == user
			end

		elsif user.role? :student
			can :update, User
			can [:read,:view], Profile
			can [:edit,:update, :picture], Profile# do |profile|
				#profile && profile.user == user
			#end
			can [:new, :create, :read], [Award,Education,Research,Workplace,Activity,Family]
			can [:edit, :update, :destroy], [Award, Education, Research, Workplace,Activity,Family] do |award|
				award && award.profile.user == user
			end
		end
	end
end
